import { fakeChartData } from '../services/api';

export default {
  namespace: 'chart',

  state: {
    hasChild: true,
    generations: 0,
    totalNum: 0,
    name:'',
    gender:'M',
    genderGroupData:[],
    generationGroupData:[],
    birthPlaceGroupData:[],
    occupationGroupData:[],
    loading: false,
  },

  effects: {
    *fetch({ payload }, { call, put }) {
      const response = yield call(fakeChartData, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        hasChild: false,
        generations: 0,
        totalNum: 0,
        name:'',
        gender:'M',
        genderGroupData:[],
        generationGroupData:[],
        birthPlaceGroupData:[],
        occupationGroupData:[],
      };
    },
  },
};
